home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir36
/
ask_dos.zip
/
ASK.DOC
< prev
next >
Wrap
Text File
|
1994-03-05
|
6KB
|
171 lines
ASK.COM - Batch Enhancer
Written By: Patrick Whittle
Introduction:▐
▀▀▀▀▀▀▀▀▀▀▀▀▀▀
The program ASK.COM was assembled using Borland Turbo Assembler. It is fully
compatible with any 8086 or greater processor. It is meant for exclusive use
in DOS batch files.
The source code and documentation has been supplied for any one new to PC
assembly language who may wish to learn to program themselves, in assembler.
Most functions used in this program are fairly simple, but you should be some-
what familiar with the Intel instruction set architecture first before diving
into the code.
The technique of replacing an interrupt handler was included to demonstrate
the power of assembler programming, to introduce the reader to the concept
of the interrupt vector table, and to show the interrupt structure of the
Intel 80XXX family of processors. The most practicle use for code such as
this is in the writing of software device drivers, and TSRs.
While the operating systems emerging today like OS/2 and UNIX for the micro-
computer are very advanced, programming in assembler language may not be
necessary in the near future; but the writing of device drivers will
surely be around for quite a while on these systems. Learning some of the
techniques and methods first under DOS is a fundamental stepping stone.
Details:▐
▀▀▀▀▀▀▀▀▀
To generate an errorlevel code for the Ctrl-C combination which can be
checked via 'IF errorlevel' commands in DOS batch files, DOS functions 35h
and 25h are used to replace the Ctrl-C interrupt handler. This technique is
accomplished by using function 35h of int 21h to first save the default
interrupt handler, and later using function 25h to restore.
Function 25h of int 21h will set or modify an interrupt handler with a
segment:offset value passed via DS:DX registers. The values placed in DS:DX
before calling function 25h in the context of this program, are addresses
contained within the executable ASK.COM. The ctrlBreakHandler PROCedure
in the source file ASK.ASM will take over the Ctrl-C interrupt after function
25h has been initiated.
Before termination of the program, function 25h will be used again to restore
the default handler to point to machine code originally intended for use on
the occurrence of the Ctrl-Break interrupt (this code will display the familiar
prompt "Terminate batch job (Y/N)?" on the screen).
Using ASK.COM:▐
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
ASK can be used with or without a command-line parameter. Omitting the
command-line parameter will simply send a (Y or N)? prompt to the screen.
The length of parameter used with ASK is restricted to 127 bytes, as DOS
disallows further input at this point.
Following are examples for its use:
Example 1:
. . .
ASK Do you wish to run Microsoft Windows?
IF errorlevel == 2 goto CTRL_C
IF errorlevel == 1 goto ABORT
win %1 %2 %3
goto END
:ABORT
echo Returning to DOS.
goto END
:CTRL_C
echo Routine aborted.
. . .
:END
Example 2:
:ENTRY_POINT
ASK Do you wish to run Microsoft Windows?
IF errorlevel == 2 goto ENTRY_POINT
IF errorlevel == 1 goto ABORT
win %1 %2 %3
goto END
:ABORT
echo Returning to DOS.
goto END
. . .
:END
The reason Ctrl-C was replaced in this program is to broaden the trapping
mechanism during user input. If Ctrl-C was allowed to interrupt during the
input state of ASK, the user could then terminate the batch file.
DOS Batch files:▐
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
DOSs batch language has some restrictions in its use that must be clearly
understood. When entering an IF-THEN-ELSE type structure in a batch file
in the IF errorlevel form, you MUST check the highest possible errorlevel
first, followed by the next highest, etc. This is to ensure the conditional
block will branch correctly.
Secondly, you cannot check for a zero errorlevel. A zero errorlevel must
be handled in a CASE ELSE form as the example below illustrates:
IF errorlevel == 4 goto OPTION4
IF errorlevel == 3 goto OPTION3
IF errorlevel == 2 goto OPTION2
IF errorlevel == 1 goto OPTION1
:ELSE
command %1 %2 %3
goto END
The following table illustrates in graphic form, the related errorlevels
returned from ASK.COM, the appropriate action, and DOS syntax to accomplish
a certain conditional block:
Exit codes:▐
▀▀▀▀▀▀▀▀▀▀▀▀
╒════════╤═══════════════╤═══════════════════════════════════════════════════╕
│ Error │ Keystroke/ │ DOS Batch File Syntax: │
│ Level │ Combination │ │
╞════════╪═══════════════╪═══════════════════════════════════════════════════╡
│ │ │ │
│ 2 │ Ctrl-Break │ IF errorlevel == 2 goto CTRL_C_ROUTINE │
│ │ │ │
│ 1 │ N (no) │ IF errorlevel == 1 goto FALSE_LABEL │
│ │ │ │
│ 0 │ Y (yes) │ Here errorlevel = 0, so execute true statements │
│ │ │ │
└────────┴───────────────┴───────────────────────────────────────────────────┘
Option:▐
▀▀▀▀▀▀▀▀
/? display ask info
References:▐
▀▀▀▀▀▀▀▀▀▀▀▀
There are many great books on assembler programming and the writing of device
drivers and TSRs. Two books I use frequently are:
1. "PC Interrupts" A Programmers Reference by Ralf Brown, and Jim Kyle
Addison-Wesley Publishing Company, Inc., 1991
ISBN 0-201-57797-6
2. "Assembly Language Programming for the Intel 80XXX Family" by William Giles,
Macmillan Publishing Company, New York, 1991
ISBN 0-02-342990-9